package com.zyz.friend.controller.user;

import com.zyz.common.core.constants.HttpConstants;
import com.zyz.common.core.model.LoginUserVO;
import com.zyz.common.core.model.Result;
import com.zyz.friend.aspect.CheckUserStatus;
import com.zyz.friend.model.user.dto.UserCodeDTO;
import com.zyz.friend.model.user.dto.UserEditDTO;
import com.zyz.friend.model.user.dto.UserLoginDTO;
import com.zyz.friend.model.user.dto.UserUpHeadDTO;
import com.zyz.friend.model.user.vo.UserVO;
import com.zyz.friend.service.user.IUserService;
import org.junit.jupiter.api.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Tag(value = "C端用户接口")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping(value = "/sendCode",method = RequestMethod.POST)
    public Result<Void> sendCode (@RequestBody UserCodeDTO userCodeDTO) {
        userService.sendCode(userCodeDTO);
        return Result.ok();
    }

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public Result<String> login (@RequestBody UserLoginDTO userLoginDTO) {
        return Result.ok(userService.login(userLoginDTO));
    }

    @RequestMapping(value = "/logout",method = RequestMethod.DELETE)
    public Result<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return userService.logout(token) ? Result.ok() : Result.fail();
    }

    @RequestMapping(value = "/info",method = RequestMethod.GET)
    public Result<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return userService.info(token);
    }

    @RequestMapping(value = "/detail",method = RequestMethod.GET)
    public Result<UserVO> detail() {
        return Result.ok(userService.detail());
    }

    @CheckUserStatus
    @RequestMapping(value = "/edit",method = RequestMethod.PUT)
    public Result<Void> edit(@RequestBody UserEditDTO userEditDTO) {
        userService.edit(userEditDTO);
        return Result.ok();
    }

    @CheckUserStatus
    @RequestMapping(value = "/updateHeadImage",method = RequestMethod.PUT)
    public Result<Void> updateHeadImage(@RequestBody UserUpHeadDTO userUpHeadDTO) {
        userService.updateHeadImage(userUpHeadDTO);
        return Result.ok();
    }

}
